
package protocol.meta;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * 主题信息
 *
 * @author MR
 */
public class Subject {

    // 主题id
    public int subjectId;// 3143",
    // 主题名称
    public String subjectName;// 地下城与勇士",
    // 主题源头像
    public String avatar;// http://nos.netease.com/buck-x1/pic/2013/05/16/18/32/21/1/54x54.png",
    // 主题页背景
    public String headImageUrl;// http://nos.netease.com/buck-x1/pic/2013/05/16/18/31/56/9/1主题页背景图.png",
    // 主题描述
    public String subjectDesc;// 《地下城与勇士》是一款2D卷轴式横版格斗过关网络游戏，大量继承了众多家用机、街机2D格斗游戏的特色，真正意义地实现了网络领域的格斗体验，具备领域独创性。",
    // 订阅数
    public int subscribeCount;// 9,
    // 我订阅该主题数目
    public int mySubCount;// 0,
    // bannerImageUrl
    public String bannerUrl;
    // 资讯源列表
    public List<Source> sourceList;


    public Subject(JSONObject json) {
        if (null == json) {
            return;
        }
        subjectId = json.optInt("subjectId");
        subjectName = json.optString("subjectName");
        avatar = json.optString("avatar");
        headImageUrl = json.optString("headImageUrl");
        subjectDesc = json.optString("subjectDesc");
        subscribeCount = json.optInt("subscribeCount");
        mySubCount = json.optInt("mySubCount");
        bannerUrl = json.optString("bannerUrl");
        sourceList = new ArrayList<Source>();
        JSONArray array = json.optJSONArray("sourceList");
        if(array != null){
            for (int i = 0; i < array.length(); i++) {
                JSONObject sourceJson = array.optJSONObject(i);
                Source source = new Source(sourceJson);
                sourceList.add(source);
            }
        }
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        sb.append("subjectId:").append(subjectId)
        .append(", subjectName:").append(subjectName)
        .append(", avatar:").append(avatar)
        .append(", headImageUrl:").append(headImageUrl)
        .append(", avatar:").append(avatar)
        .append(", subjectDesc:").append(subjectDesc)
        .append(", subscribeCount:").append(subscribeCount)
        .append(", mySubCount:").append(mySubCount)
        .append(", bannerUrl:").append(bannerUrl)
        .append(", sourceList:").append(sourceList);
        sb.append("}");
        return sb.toString();
    }
}
